package com.itheima.remark.dao;

import com.itheima.pojo.Product;
import com.remark.search.pojo.RemarkImfo;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import sun.awt.SunHints;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface ProductMapper extends Mapper<Product> {


    @Select("SELECT p.id,p.name,c.name categoryName,p.score,p.money,p.images images,p.time_scpe timeScpe,a.precision,a.dimensionality,a.address_name addressName,(select count(com.id) from `product` p,`comment` com where p.`id`=com.`product_id`) commentCount FROM `product` p,`category` c,`addresses` a  WHERE p.`address_id`=a.`id` AND p.`category_id`=c.`id`")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "precision" ,property = "location.lat",javaType = double.class),
            @Result(column = "dimensionality" ,property = "location.lon"),
    })
    List<RemarkImfo> selectAllRemarkImfo();

    @Select("select count(id) from `product`")
    int selectCountAll();

    @Select("SELECT p.id,p.name,c.name categoryName,p.score,p.money,p.images images,p.time_scpe timeScpe,a.precision,a.dimensionality,a.address_name addressName,(select count(com.id) from `product` p,`comment` com where p.`id`=com.`product_id` and p.id = #{id} ) commentCount FROM `product` p,`category` c,`addresses` a  WHERE p.`address_id`=a.`id` AND p.`category_id`=c.`id` and p.id = #{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "precision" ,property = "location.lat",javaType = double.class),
            @Result(column = "dimensionality" ,property = "location.lon"),
    })
    RemarkImfo selectInfoById(Integer id);
}
